package source.model;

import source.model.type.GameObjectType;
import source.model.type.TerrainType;

public class Terrain implements GameObject{
	
	private final GameObjectType gameObjectType = GameObjectType.TERRAIN;
	private static int nextId = 0;
	private final ObjectID oid;
	private TerrainType tType;
	private boolean isValid;
	
	public Terrain(TerrainType t){
		oid = new ObjectID ( gameObjectType.getId() + "." + nextId++);
		tType = t;
		this.isValid = true;
	}
	
	public boolean isValid(){
		return isValid;
	}
	
	public float getMvRate() {
		return (float)this.tType.getMvRate();
	}
	
	public ObjectID objectID(){
		return oid;
	}
	public GameObjectType objectType(){
		return gameObjectType;
	}
	
	public boolean isPlayerOwned(){
		return false;
	}
	
	public TerrainType getType()
	{
		return tType;
	}
	
	/**
	 * This method is used to mark the object as having been forcibly moved (i.e.,
	 * Unit teleported using Area Effect) and that it's possition needs to be changed.
	 * @param x new x-coordinate
	 * @param y new y-coordinate
	 * @return true if object allowed the forced change, false otherwise
	 */
	public boolean changePosition( int x, int y ){
		//TODO:  implement method
		return true;
	}
	
	/**
	 * Queries the object to find out if the changePositionFlag is set, meaning
	 * the object's position in pMap must be updated
	 * @return true if flag set; false otherwise
	 */
	public boolean changePositionFlag(){
		//TODO:  implement method
		return false;
	}
	
	public Position newPosition(){
		//TODO: implement method
		return new Position(0, 0);
	}
	
	/**
	 * Once the DataHandler resets the position of the object, it calls this method to
	 * let the object know that it is now no longer in a "Forced Position Change" 
	 * state
	 * @return true if the object reset it's flag, false otherwise
	 */
	public boolean resetPositionChangedFlag(){
		//TODO:  implement method
		return true;
		
	}
	
	public void invalidate()
	{
		isValid = false;
	}
	
	public java.util.Hashtable<String, String> getViewData()
	{
		java.util.Hashtable<String, String> viewData = new java.util.Hashtable<String, String>();
		
		viewData.put("Object ID", oid.getID());
		viewData.put("Game Object Type", gameObjectType.name());
		viewData.put("Terrain Type", tType.getName());
		viewData.put("Terrain Message", tType.getMsg());
		viewData.put("Terrain Movement Cost", Integer.toString(tType.getMvRate()));
				
		return viewData;
	}
}
